using System;
using System.Drawing;

public class AdobeColors
{
    public static Color CMYK_to_RGB(CMYK _cmyk)
    {
        int red = Round(255.0 - (255.0 * _cmyk.C));
        int green = Round(255.0 - (255.0 * _cmyk.M));
        int blue = Round(255.0 - (255.0 * _cmyk.Y));
        return Color.FromArgb(red, green, blue);
    }

    public static Color HSL_to_RGB(HSL hsl)
    {
        int num2;
        int red = Round(hsl.L * 255.0);
        int blue = Round(((1.0 - hsl.S) * (hsl.L / 1.0)) * 255.0);
        double num4 = ((double) (red - blue)) / 255.0;
        if ((hsl.H >= 0.0) && (hsl.H <= 0.16666666666666666))
        {
            num2 = Round((((hsl.H - 0.0) * num4) * 1530.0) + blue);
            return Color.FromArgb(red, num2, blue);
        }
        if (hsl.H <= 0.33333333333333331)
        {
            return Color.FromArgb(Round((-((hsl.H - 0.16666666666666666) * num4) * 1530.0) + red), red, blue);
        }
        if (hsl.H <= 0.5)
        {
            num2 = Round((((hsl.H - 0.33333333333333331) * num4) * 1530.0) + blue);
            return Color.FromArgb(blue, red, num2);
        }
        if (hsl.H <= 0.66666666666666663)
        {
            num2 = Round((-((hsl.H - 0.5) * num4) * 1530.0) + red);
            return Color.FromArgb(blue, num2, red);
        }
        if (hsl.H <= 0.83333333333333337)
        {
            return Color.FromArgb(Round((((hsl.H - 0.66666666666666663) * num4) * 1530.0) + blue), blue, red);
        }
        if (hsl.H <= 1.0)
        {
            num2 = Round((-((hsl.H - 0.83333333333333337) * num4) * 1530.0) + red);
            return Color.FromArgb(red, blue, num2);
        }
        return Color.FromArgb(0, 0, 0);
    }

    public static Color ModifyBrightness(Color c, double brightness)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.L *= brightness;
        return HSL_to_RGB(hsl);
    }

    public static Color ModifyHue(Color c, double Hue)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.H *= Hue;
        return HSL_to_RGB(hsl);
    }

    public static Color ModifySaturation(Color c, double Saturation)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.S *= Saturation;
        return HSL_to_RGB(hsl);
    }

    public static CMYK RGB_to_CMYK(Color c)
    {
        CMYK cmyk = new CMYK();
        double m = 1.0;
        cmyk.C = ((double) (0xff - c.R)) / 255.0;
        if (m > cmyk.C)
        {
            m = cmyk.C;
        }
        cmyk.M = ((double) (0xff - c.G)) / 255.0;
        if (m > cmyk.M)
        {
            m = cmyk.M;
        }
        cmyk.Y = ((double) (0xff - c.B)) / 255.0;
        if (m > cmyk.Y)
        {
            m = cmyk.Y;
        }
        if (m > 0.0)
        {
            cmyk.K = m;
        }
        return cmyk;
    }

    public static HSL RGB_to_HSL(Color c)
    {
        int r;
        int g;
        double num4;
        HSL hsl = new HSL();
        if (c.R > c.G)
        {
            r = c.R;
            g = c.G;
        }
        else
        {
            r = c.G;
            g = c.R;
        }
        if (c.B > r)
        {
            r = c.B;
        }
        else if (c.B < g)
        {
            g = c.B;
        }
        int num3 = r - g;
        hsl.L = ((double) r) / 255.0;
        if (r == 0)
        {
            hsl.S = 0.0;
        }
        else
        {
            hsl.S = ((double) num3) / ((double) r);
        }
        if (num3 == 0)
        {
            num4 = 0.0;
        }
        else
        {
            num4 = 60.0 / ((double) num3);
        }
        if (r == c.R)
        {
            if (c.G < c.B)
            {
                hsl.H = (360.0 + (num4 * (c.G - c.B))) / 360.0;
                return hsl;
            }
            hsl.H = (num4 * (c.G - c.B)) / 360.0;
            return hsl;
        }
        if (r == c.G)
        {
            hsl.H = (120.0 + (num4 * (c.B - c.R))) / 360.0;
            return hsl;
        }
        if (r == c.B)
        {
            hsl.H = (240.0 + (num4 * (c.R - c.G))) / 360.0;
            return hsl;
        }
        hsl.H = 0.0;
        return hsl;
    }

    private static int Round(double val)
    {
        int num = (int) val;
        int num2 = (int) (val * 100.0);
        if ((num2 % 100) >= 50)
        {
            num++;
        }
        return num;
    }

    public static Color SetBrightness(Color c, double brightness)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.L = brightness;
        return HSL_to_RGB(hsl);
    }

    public static Color SetHue(Color c, double Hue)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.H = Hue;
        return HSL_to_RGB(hsl);
    }

    public static Color SetSaturation(Color c, double Saturation)
    {
        HSL hsl = RGB_to_HSL(c);
        hsl.S = Saturation;
        return HSL_to_RGB(hsl);
    }

    public class CMYK
    {
        private double _c = 0.0;
        private double _k = 0.0;
        private double _m = 0.0;
        private double _y = 0.0;

        public double C
        {
            get
            {
                return this._c;
            }
            set
            {
                this._c = value;
                this._c = (this._c > 1.0) ? 1.0 : ((this._c < 0.0) ? 0.0 : this._c);
            }
        }

        public double K
        {
            get
            {
                return this._k;
            }
            set
            {
                this._k = value;
                this._k = (this._k > 1.0) ? 1.0 : ((this._k < 0.0) ? 0.0 : this._k);
            }
        }

        public double M
        {
            get
            {
                return this._m;
            }
            set
            {
                this._m = value;
                this._m = (this._m > 1.0) ? 1.0 : ((this._m < 0.0) ? 0.0 : this._m);
            }
        }

        public double Y
        {
            get
            {
                return this._y;
            }
            set
            {
                this._y = value;
                this._y = (this._y > 1.0) ? 1.0 : ((this._y < 0.0) ? 0.0 : this._y);
            }
        }
    }

    public class HSL
    {
        private double _h = 0.0;
        private double _l = 0.0;
        private double _s = 0.0;

        public double H
        {
            get
            {
                return this._h;
            }
            set
            {
                this._h = value;
                this._h = (this._h > 1.0) ? 1.0 : ((this._h < 0.0) ? 0.0 : this._h);
            }
        }

        public double L
        {
            get
            {
                return this._l;
            }
            set
            {
                this._l = value;
                this._l = (this._l > 1.0) ? 1.0 : ((this._l < 0.0) ? 0.0 : this._l);
            }
        }

        public double S
        {
            get
            {
                return this._s;
            }
            set
            {
                this._s = value;
                this._s = (this._s > 1.0) ? 1.0 : ((this._s < 0.0) ? 0.0 : this._s);
            }
        }
    }
}

